if ( !window.JSOT )
  window.JSOT = { };
if ( !window.JSOT.wala )
  window.JSOT.wala = { };

/*******************************************************
 *
 * Global wala functions specific to Wave.
 *
 *******************************************************/

JSOT.wala.waves = function()
{
  JSOT.Wave.getEvent("newWave").addExprListener( this );
  var result = [ ];
  for( var key in JSOT.Wave.waves )
	result.push( JSOT.Wave.waves[key] );
  return result;
};

JSOT.wala.wave = function( id, domain )
{
  return JSOT.Wave.getWave( id, domain );
};

JSOT.wala.wavelets = function( wave )
{
  wave.getEvent("newWavelet").addExprListener( this );
  var result = [ ];
  var wavelets = wave.getWavelets();
  for( var key in wavelets )
	result.push( wavelets[key] ); 
  return result;
};

JSOT.wala.doc = function( wavelet, id )
{
  var doc = wavelet.getDoc(id);
  return doc;
};

JSOT.wala.docs = function(wavelet)
{
  wavelet.getEvent("newDoc").addExprListener( this );
  var result = [ ];
  var docs = wavelet.getDocs();
  for( var key in docs )
	result.push( docs[key] );
  return result;
};

/*******************************************************
 *
 * Wala extensions to match the JSOT document model with the API
 * wala expects from a document model.
 *
 *******************************************************/

/**
 * Allows code such as "element.foo" to read the foo attribute of an element.
 */
JSOT.Doc.ElementStart.prototype.getValueAndListen = function( attrib, expr )
{
  this.getEvent("attributeChange").addExprListener( expr );
  if ( !this.attributes )
	return null;
  return this.attributes[ attrib ];
};

